Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix realloc method for ChibiOS #13820

Merged
merged 8 commits into from
Mar 23, 2020
Merged

Conversation

bugobliterator
Copy link
Member

realloc method is left undefined, hence calling libc method that breaks realloc in AP_ExpandingArray used in Dijkstra Avoidance code.

@tridge
Copy link
Contributor

tridge commented Mar 17, 2020

@bugobliterator I presume the breakage is because it doesn't zero-fill the added memory?
If we are going to ban ::realloc() then we should ensure we get a build error if anyone uses it. Also, why the std_realloc() name? Maybe it should be realloc_type() and use the type like malloc_type() does?

@bugobliterator
Copy link
Member Author

@bugobliterator I presume the breakage is because it doesn't zero-fill the added memory?
If we are going to ban ::realloc() then we should ensure we get a build error if anyone uses it. Also, why the std_realloc() name? Maybe it should be realloc_type() and use the type like malloc_type() does?

It just failed to realloc, my assumption is that we are using malloc that we defined and trying to call libc realloc on that pointer, I don't think that would work.

Regarding the name, I don't care much about it, I just wanted some way to distance from heap_realloc allocator from specified heap with common heap realloc. So whatever your preference I can implement that.

@bugobliterator
Copy link
Member Author

@tridge Also introduced error when libc realloc is used for ChibiOS builds.

@bugobliterator
Copy link
Member Author

bugobliterator commented Mar 17, 2020

@tridge @WickedShell the check added above to produce error whenever realloc is being used, has detected use of realloc under lua scripting, can you review and push the necessary fix to this branch?

The error is as follows:

./../libraries/AP_Scripting/lua/src/lauxlib.c: In function 'l_alloc':
../../libraries/AP_Scripting/lua/src/lauxlib.c:1015:5: error: 'realloc' is deprecated [-Werror=deprecated-declarations]
     return realloc(ptr, nsize);
     ^~~~~~
compilation terminated due to -Wfatal-errors.
cc1: some warnings being treated as errors

@WickedShell
Copy link
Contributor

@bugobliterator I can't push to it, but you can just comment out that whole section. It's actually unused, as we don't ever call that function.

diff --git a/libraries/AP_Scripting/lua/src/lauxlib.c b/libraries/AP_Scripting/lua/src/lauxlib.c
index 8bdada50a7..b4948e3395 100644
--- a/libraries/AP_Scripting/lua/src/lauxlib.c
+++ b/libraries/AP_Scripting/lua/src/lauxlib.c
@@ -1005,29 +1005,29 @@ LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,
 }
 
 
-static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
-  (void)ud; (void)osize;  /* not used */
-  if (nsize == 0) {
-    free(ptr);
-    return NULL;
-  }
-  else
-    return realloc(ptr, nsize);
-}
-
-
-static int panic (lua_State *L) {
-  lua_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n",
-                        lua_tostring(L, -1));
-  return 0;  /* return to Lua to abort */
-}
-
-
-LUALIB_API lua_State *luaL_newstate (void) {
-  lua_State *L = lua_newstate(l_alloc, NULL);
-  if (L) lua_atpanic(L, &panic);
-  return L;
-}
+//static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
+//  (void)ud; (void)osize;  /* not used */
+//  if (nsize == 0) {
+//    free(ptr);
+//    return NULL;
+//  }
+//  else
+//    return realloc(ptr, nsize);
+//}
+//
+//
+//static int panic (lua_State *L) {
+//  lua_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n",
+//                        lua_tostring(L, -1));
+//  return 0;  /* return to Lua to abort */
+//}
+//
+//
+//LUALIB_API lua_State *luaL_newstate (void) {
+//  lua_State *L = lua_newstate(l_alloc, NULL);
+//  if (L) lua_atpanic(L, &panic);
+//  return L;
+//}
 
 
 LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver, size_t sz) {

@tridge tridge merged commit edaf9fa into ArduPilot:master Mar 23, 2020
@rmackay9
Copy link
Contributor

rmackay9 commented May 6, 2020

This is included in Copter-4.0.4-rc1

@rmackay9 rmackay9 moved this from PRs to 4.0.4-rc1 in Copter 4.0 backports May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Plane 4.0 Backports
  
Awaiting triage
Rover 4.0 backports
Awaiting triage
Development

Successfully merging this pull request may close these issues.

None yet

6 participants